<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="s" uri="http://www.springframework.org/tags/form" %>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE html><html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>仓库管理</title>
    <style>
        .newtitle {
            PADDING-LEFT: 15px;
            BACKGROUND: url('');
            PADDING-BOTTOM: 4px;
            BORDER-LEFT: #c0dcf2 1px solid;
        }
    </style>
    <jsp:include page="easyuiIncludeJS.jsp"/>
    <script type="text/javascript">
        $(function () {
            var pager = $(".easyui-datagrid").datagrid('getPager');
            $(pager).pagination({
                total:${pager.totalRows},
                pageSize:${pager.pageRow},
                displayMsg: '{from}-{to}/{total}',
                pageNumber:${pager.cur_page},
                afterPageText: '页，共{pages}页',
                pageList: [30, 600, 900, 3000, 5000, 10000],
                loading: false,
                showPageList: true,
                showRefresh: true,
                //刷新方法
                onBeforeRefresh: function (p, s) {
                    location.href = "${pageContext.request.contextPath }/admin/storage/list?cur_page=" + p + "&pageRow=" + s;
                },
                onSelectPage: function (p, s) {
                    location.href = "${pageContext.request.contextPath }/admin/storage/list?cur_page=" + p + "&pageRow=" + s;
                }
            });
        });


        function edit(value, rec) {
            var storageId = rec.storageId;
            var storageCode = rec.storageCode;
            var storageName = rec.storageName;
            var chairman = rec.chairman;
            var tel = rec.tel;
            var position = rec.position;
            var url = "${pageContext.request.contextPath}/admin/storage/json";
            $.post(
                url,
                {
                    "storageId": storageId,
                    "storageCode": storageCode,
                    "storageName": storageName,
                    "chairman":chairman,
                    "tel":tel,
                    "position":position
                    
                },
                updemp,
                "json"
            );
        }

        function updemp(date) {
            $("#storageId").val(date.storageList.storageId);
            $("#storageCode").val(date.storageList.storageCode);
            $("#storageName").val(date.storageList.storageName);
            $("#chairman").val(date.storageList.chairman);
            $("#tel").val(date.storageList.tel);
            $("#position").val(date.storageList.position);
        }

        function add() {
            var url = "${pageContext.request.contextPath}/admin/storage/add"
            var storageId = $("#storageId").val();
            var storageCode = $("#storageCode").val();
            var storageName = $("#storageName").val();
            var chairman = $("#chairman").val();
            var tel = $("#tel").val();
            var position = $("#position").val();
            if(storageCode==""){
            	alert("请输入代码");
            	$("#storageCode").focus();
            	return;
            }
            if(storageName==""){
            	alert("请输入名称");
            	$("#storageName").focus();
            	return;
            }
            
            $.post(
                url,

                {
                    "storageId": storageId,
                    "storageCode": storageCode,
                    "storageName": storageName,
                    "chairman":chairman,
                    "tel":tel,
                    "position":position
                },
                function (data) {
                    window.location.href = "${pageContext.request.contextPath }/admin/storage/list";
                }
            )
        }
    </script>
</head>
<body>
<table class="easyui-datagrid" pagination="true" fitColumns="true" style="height:400px" singleSelect="true"
       data-options="onClickRow:edit">
    <thead>
    <tr>
        <th align="center" width="100" field="storageId">编号</th>
        <th align="center" width="200" field="storageCode">仓库代码</th>
        <th align="center" width="200" field="storageName">仓库名称</th>
        <th align="center" width="200" field="chairman">负责人</th>
        <th align="center" width="200" field="tel">联系电话</th>
        <th align="center" width="200" field="position">仓库位置</th>
        <th align="center" width="200" field="opt">操作</th>
    </tr>
    </thead>
    <tbody>
    <c:forEach items="${pager.datas}" var="d">
        <tr>
            <td>${d.storageId}</td>
            <td>${d.storageCode}</td>
            <td>${d.storageName}</td>
            <td>${d.chairman}</td>
            <td>${d.tel}</td>
            <td>${d.position}</td>
            <td>
                <a href="${pageContext.request.contextPath}/admin/storage/del?storageId=${d.storageId}" class="easyui-linkbutton" plain="true" icon="icon-remove"
                   onclick="return confirm('删除确定');"> 删除</a>
                <a href='javascript:void(0);' class="easyui-linkbutton" plain="true" icon="icon-undo" onclick='edit();'>编辑</a>
            </td>
        </tr>
    </c:forEach>
    </tbody>
</table>
<div id="tt" class="easyui-tabs" style="height:150px">
    <div title="仓库信息管理" data-options="closable:false,cache:false" style="padding:0px;">
        <div class="newtitle">
            <th>
                <a class="easyui-linkbutton" plain="true" icon="icon-save" href="javascript:void(0);"
                   onclick="return add();">保存</a>
            </th>
        </div>
        <form name="form1" enctype="multipart/form-data" method="post">
            <hidden id="storageId" name="storageId"></hidden>
            <table width="100%" align="center" style="margin-top: 5px;">
                <tr height="40px">
                    <td align="right">仓库代码：</td>
                    <td>
                        <input class="easyui-textbox" id="storageCode" name="storageCode"
                               data-options="prompt:'请输入仓库代码',validType:'text'"><font color="red">必须唯一</font>
                    </td>
                    <td align="right">仓库名称：</td>
                    <td>
                        <input class="easyui-textbox" id="storageName" name="storageName"
                               data-options="prompt:'请输入仓库名称',validType:'text'">
                    </td>
                    <td align="right">负责人：</td>
                    <td>
                        <input class="easyui-textbox" id="chairman" name="chairman"
                               data-options="prompt:'请输入仓库负责人',validType:'text'">
                    </td>
                </tr>
                <tr height="40px">
                    <td align="right">联系电话：</td>
                    <td>
                        <input class="easyui-textbox" id="tel" name="tel"
                               data-options="prompt:'请输入联系电话',validType:'text'">
                    </td>
                	<td align="right">仓库位置：</td>
                    <td colspan="3">
                        <input class="easyui-textbox" id="position" name="position"
                               data-options="prompt:'请输入仓库位置',validType:'text'" style="width:600px">
                    </td>
                </tr>
            </table>
        </form>
    </div>
</div>
</body>
</html>
